\\ HECC
\\ simple GP codes, in order to illustrate the addition
\\ on the Jacobian of an hyperelliptic curve.
\\ The code translate easily the algorithms given in the lectures.
\\ Ph. Elbaz-Vincent.

JacobianAdd(D1,D2)=
{
 \\ we suppose fixed a hyperelliptic curve F(x,y)=0 over
 \\ a ground field Z/pZ (so p is also fixed) and the genus g
 \\ also. We also fixed f and h from the equation. 
 \\ All of them are global data.

 \\ D1 and D2 are vector [a1,b1], [a2,b2] of reduced divisors
 \\ we should check for reduction of divisors

 local(e,c,a,b,a1,a2,b1,b2);

 a1=D1[1]; a2=D2[1]; b1=D1[2]; b2=D2[2]; 
 e=bezout(a1,a2); \\ d1=e[3]
 c=bezout(e[3],b1+b2+h); \\ d=c[3]
 a=a1*a2/sqr(c[3]);
 b=((c[1]*e[1]*a1*b2+c[1]*e[2]*a2*b1+c[2]*(b1*b2+f))/c[3]);
 if(b!=0,b=b % a); \\ a stupid stuff, due to PARI/GP error.

 \\ now we need to reduce it

 while(poldegree(a)>g,a=(f-b^2-h*b)/a;b=(-h-b) %a;);
 a=a/pollead(a);

 return([a,b]);
} /* end of JacobianAdd */
